﻿using System.Collections.Generic;
using System.Web.Mvc;
using InvoiceInvoker.Logic;

namespace InvoiceInvoker.MvcUI.Helpers
{
	public static class HtmlHelpers
	{
		public static string Truncate(this HtmlHelper helper, string text, int length)
		{
			if (text == null)
			{
				return "";
			}
			else if (text.Length <= length)
			{
				return text;
			}
			else
			{
				return text.Substring(0, length) + "...";
			}
		}

		private static string TranslateInvoiceStatus(string status)
		{
			if (status == Invoice.InvoiceStatus.Created.ToString())
				return "Wystawiona";
			else if (status == Invoice.InvoiceStatus.Paid.ToString())
				return "Zapłacona";
			else
				return "";
		}

		public static string TranslateInvoiceStatus(this HtmlHelper helper, string status)
		{
			return TranslateInvoiceStatus(status);
		}

		public static List<KeyValuePair<string, string>> GetInvoiceStatusList(this HtmlHelper helper)
		{
			List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
			
			result.Add(new KeyValuePair<string, string>(TranslateInvoiceStatus(Invoice.InvoiceStatus.Created.ToString()), Invoice.InvoiceStatus.Created.ToString()));
			result.Add(new KeyValuePair<string, string>(TranslateInvoiceStatus(Invoice.InvoiceStatus.Paid.ToString()), Invoice.InvoiceStatus.Paid.ToString()));

			return result;
		}
	}
}